using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class LOAINGUOIDUNGRepository
	{
		public static List<LOAINGUOIDUNG> SelectAll()
		{
			return DataContext.Instance.LOAINGUOIDUNG.OrderBy(item => item.TEN_LOAI_NGUOI_DUNG).ToList();
		}

		public static LOAINGUOIDUNG SelectByID(int maLOAINGUOIDUNG)
		{
			return DataContext.Instance.LOAINGUOIDUNG.FirstOrDefault(item => item.LOAI_NGUOI_DUNG_ID == maLOAINGUOIDUNG );
		}

		public static bool Insert(LOAINGUOIDUNG obj)
		{
			try
			{
				DataContext.Instance.LOAINGUOIDUNG.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int maLOAINGUOIDUNG)
		{
			try
			{
				var delitem = DataContext.Instance.LOAINGUOIDUNG.FirstOrDefault(item => item.LOAI_NGUOI_DUNG_ID == maLOAINGUOIDUNG );
				DataContext.Instance.LOAINGUOIDUNG.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<LOAINGUOIDUNG> RetrieveByID(int maLOAINGUOIDUNG)
		{
			return (from item in DataContext.Instance.LOAINGUOIDUNG where  item.LOAI_NGUOI_DUNG_ID == maLOAINGUOIDUNG  select item).ToList();
		}
	}
}